package com.lhn.spring5.dao;

import com.lhn.spring5.entity.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * 账号操作
 *
 * @author lhn
 * @date 2022/01/06 14:22
 * @since 1.0.0
 **/
@Repository
public class AccountDaoImpl implements AccountDao{

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 账户增加
     *
     * @param account 账户信息
     */
    @Override
    public void addAccount(Account account) {
        String sql = "update `t_account` set `money` = `money` + ? where `username` = ?";
        jdbcTemplate.update(sql, account.getMoney(), account.getUsername());
    }

    /**
     * 账户减少
     *
     * @param account 账户信息
     */
    @Override
    public void reduceAccount(Account account) {
        String sql = "update `t_account` set `money` = `money` - ? where `username` = ?";
        jdbcTemplate.update(sql, account.getMoney(), account.getUsername());
    }
}